package com.fr.data.impl;

import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONObject;
import com.fr.base.file.DatasourceManager;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.Semantic;
import com.fr.data.TableData;

public class ADHOCNamedTableData extends ADHOCTableData
{
  public static int TYPE = 0;
  private String dbTableDataName = null;

  public ADHOCNamedTableData()
  {
  }

  public ADHOCNamedTableData(String paramString1, String paramString2, Semantic paramSemantic)
  {
    this.dbTableDataName = paramString1;
    setDescription(paramString2);
    setSemantic(paramSemantic);
  }

  protected TableData createTableData()
  {
    if (this.dt == null)
    {
      DatasourceManager localDatasourceManager = FRContext.getDatasourceManager();
      if (StringUtils.isNotEmpty(this.dbTableDataName))
        this.dt = localDatasourceManager.getTableData(this.dbTableDataName);
    }
    return this.dt;
  }

  public String getDbTableDataName()
  {
    return this.dbTableDataName;
  }

  public void setDbTableDataName(String paramString)
  {
    this.dbTableDataName = paramString;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("DBTableDataName".equals(str))
        setDbTableDataName(paramXMLableReader.getElementValue());
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (StringUtils.isNotEmpty(this.dbTableDataName))
      paramXMLPrintWriter.startTAG("DBTableDataName").textNode(this.dbTableDataName).end();
  }

  public void parseJSON(JSONObject paramJSONObject)
    throws Exception
  {
    super.parseJSON(paramJSONObject);
    if (paramJSONObject.has("dbTableDataName"))
      setDbTableDataName(paramJSONObject.getString("dbTableDataName"));
  }

  public JSONObject createJSON()
    throws Exception
  {
    JSONObject localJSONObject = super.createJSON();
    localJSONObject.put("type", TYPE);
    if (StringUtils.isNotEmpty(this.dbTableDataName))
      localJSONObject.put("dbTableDataName", getDbTableDataName());
    return localJSONObject;
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof ADHOCNamedTableData) && (ComparatorUtils.equals(getDescription(), ((ADHOCNamedTableData)paramObject).getDescription())) && (ComparatorUtils.equals(this.dbTableDataName, ((ADHOCNamedTableData)paramObject).dbTableDataName)) && (ComparatorUtils.equals(getSemantic(), ((ADHOCNamedTableData)paramObject).getSemantic())));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ADHOCNamedTableData localADHOCNamedTableData = (ADHOCNamedTableData)super.clone();
    localADHOCNamedTableData.setDbTableDataName(this.dbTableDataName);
    return localADHOCNamedTableData;
  }
}